<template>
  <div class="app-container">
    <el-form  ref="form" :model="form" :rules="rules" label-width="150px">
      <h3 class="inner-title">规则一</h3>
      <div style="padding: 0 15px">
        <el-row :gutter="20">
          <el-col :span="20">
            <el-form-item required label="工单维护时间设置" prop="linkCity">
              <el-input placeholder="工单维护时间设置"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button icon="el-icon-check"  type="primary" @click="submitForm">保存规则信息</el-button>
          </el-col>
        </el-row>
      </div>
      <h3 class="inner-title">规则二</h3>
      <div style="padding: 0 15px">
        <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item required label="车型" prop="linkUrl">
              <el-select multiple filterable v-model="form.linkCity" style="width: 100%;" placeholder="请选择车型">
                <el-option label="大型普通客车" value="1"></el-option>
                <el-option label="中型专用校车" value="2"></el-option>
                <el-option label="大型专用校车" value="3"></el-option>
                <el-option label="小型轿车" value="4"></el-option>
                <el-option label="重型半挂车牵引车" value="4"></el-option>
                <el-option label="重型普通货车" value="4"></el-option>
                <el-option label="重型特殊结构货车" value="4"></el-option>
                <el-option label="重型仓栅式货车" value="4"></el-option>
                <el-option label="重型罐式货车" value="4"></el-option>
                <el-option label="重型栏板货车" value="4"></el-option>
                <el-option label="重型自卸货车" value="4"></el-option>
                <el-option label="重型厢式货车" value="4"></el-option>
                <el-option label="中型厢式货车" value="4"></el-option>
                <el-option label="轻型厢式货车" value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item required label="车辆超期时间设置" prop="linkCity">
              <el-input placeholder="车辆超期时间设置"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button icon="el-icon-check"  type="primary" @click="submitForm">保存规则信息</el-button>
          </el-col>
        </el-row>
      </div>
      <h3 class="inner-title">规则三</h3>
      <div style="padding: 0 15px">
        <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item required label="二级维护站" prop="linkUrl">
              <el-select multiple filterable v-model="form.linkCity" style="width: 100%;" placeholder="请选择二级维护站">
                <el-option label="维护站一" value="1"></el-option>
                <el-option label="维护站二" value="2"></el-option>
                <el-option label="维护站三" value="3"></el-option>
                <el-option label="维护站四" value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item required label="经营范围" prop="linkUrl">
              <el-input v-model="form.spoce" placeholder="经验范围" type="textarea"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button icon="el-icon-check"  type="primary" @click="submitForm">保存规则信息</el-button>
          </el-col>
        </el-row>
      </div>
      <h3 class="inner-title">规则四</h3>
      <div style="padding: 0 15px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="二级维护站" required prop="linkUrl">
              <el-select multiple filterable v-model="form.linkCity" style="width: 100%;" placeholder="请选择二级维护站">
                <el-option label="维护站一" value="1"></el-option>
                <el-option label="维护站二" value="2"></el-option>
                <el-option label="维护站三" value="3"></el-option>
                <el-option label="维护站四" value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="计量证书照片"  required prop="linkUrl">
              <image-upload></image-upload>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="开始日期" required prop="">
              <el-input v-model="form.spoce" placeholder="证书开始日期" ></el-input>
            </el-form-item>
             <el-form-item label="结束日期" required prop="">
              <el-input v-model="form.spoce" placeholder="证书结束日期" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button icon="el-icon-check"  type="primary" @click="submitForm">保存规则信息</el-button>
          </el-col>
        </el-row>
      </div>
    </el-form>

    <!-- 添加或修改非道路-联网信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="地市" prop="linkCity">
          <el-select v-model="form.linkCity" placeholder="请选择地市">
            <el-option
              v-for="dict in dict.type.sx_city"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="地址" prop="linkUrl">
          <el-input v-model="form.linkUrl" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="用户名" prop="linkName">
          <el-input v-model="form.linkName" placeholder="请输入用户名" />
        </el-form-item>
        <el-form-item label="密码" prop="linkPwd">
          <el-input v-model="form.linkPwd" placeholder="请输入密码" />
        </el-form-item>
        <el-form-item label="token" prop="linkToken">
          <el-input v-model="form.linkToken" placeholder="请输入token" />
        </el-form-item>
        <el-form-item label="appid" prop="linkAppid">
          <el-input v-model="form.linkAppid" placeholder="请输入appid" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSecondary, getSecondary, delSecondary, addSecondary, updateSecondary, controlShow,updateStatus,wxUnitList } from "@/api/maintenanceenterprise/secondarysite";
import { getDistrictTreeList,selectOrgCodeName } from "@/api/system/district";
import { getToken } from "@/utils/auth";
export default {
  name: "Secondary",
  dicts: ['sx_city'],
  data() {
    return {
      dateRange: [new Date(2025, 9, 1, 8, 0), new Date(2025, 10, 1, 8, 0)],
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      controlShow: false,
      props: {
        label: "name",
        value: "code",
        children: "chridrenList"
      },
      wxUnitList: [],
      options: [],
      fileList: [],
      accept: ".xls,.xlsx",
      importUrl: process.env.VUE_APP_BASE_API + "/vehicleservice/secondary/import/data",
      openImportData: false,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 4,
      // 汽车检测-二级维护站表格数据
      orderList: [
        {
          workOrderNumber: 'TEST202510310001',
          repairSiteName: '王小虎',
          plateNo: '鲁A12345',
          orderStatus: '3',
          startTime: '2025-10-29 10:00:00',
          endTime: '2025-10-31 10:00:00',
          createTime: '2025-10-29 10:00:00',
          jinChangImg: 'https://wx2.sinaimg.cn/mw690/dcb19d29ly1i3qh75gioaj20n00gt41p.jpg',
          junGongImg: 'https://wx1.sinaimg.cn/mw690/71cea2dagy1i6qdooz0q5j20u018q0zb.jpg',
          jieSuanImg: 'https://wx4.sinaimg.cn/mw690/a6ca17dbgy1i4x4vi732zj21400r8gtq.jpg',
          weiXiuImg: 'https://wx4.sinaimg.cn/mw690/a6ca17dbgy1i4x4vi732zj21400r8gtq.jpg',
          heGeImg: 'https://wx4.sinaimg.cn/mw600/e605b254ly1i6tld21nonj20u014013g.jpg',
          orgName: '兰山区',
          warningReason:"规定时间:3小时,时间维修时间:2小时，实际维修时间小于规定时间 1小时"
        },{
          workOrderNumber: 'TEST202510310001',
          repairSiteName: '王小虎',
          plateNo: '鲁A12345',
          orderStatus: '3',
          startTime: '2025-10-29 10:00:00',
          endTime: '2025-10-31 10:00:00',
          createTime: '2025-10-29 10:00:00',
          jinChangImg: 'https://wx2.sinaimg.cn/mw690/dcb19d29ly1i3qh75gioaj20n00gt41p.jpg',
          junGongImg: 'https://wx1.sinaimg.cn/mw690/71cea2dagy1i6qdooz0q5j20u018q0zb.jpg',
          jieSuanImg: 'https://wx4.sinaimg.cn/mw690/a6ca17dbgy1i4x4vi732zj21400r8gtq.jpg',
          weiXiuImg: 'https://wx4.sinaimg.cn/mw690/a6ca17dbgy1i4x4vi732zj21400r8gtq.jpg',
          heGeImg: 'https://wx4.sinaimg.cn/mw600/e605b254ly1i6tld21nonj20u014013g.jpg',
          orgName: '兰山区',
          warningReason:"规定时间:3小时,时间维修时间:2小时，实际维修时间小于规定时间 1小时"
        },{
          workOrderNumber: 'TEST202510310001',
          repairSiteName: '王小虎',
          plateNo: '鲁A12345',
          orderStatus: '3',
          startTime: '2025-10-29 10:00:00',
          endTime: '2025-10-31 10:00:00',
          createTime: '2025-10-29 10:00:00',
          jinChangImg: 'https://wx2.sinaimg.cn/mw690/dcb19d29ly1i3qh75gioaj20n00gt41p.jpg',
          junGongImg: 'https://wx1.sinaimg.cn/mw690/71cea2dagy1i6qdooz0q5j20u018q0zb.jpg',
          jieSuanImg: 'https://wx4.sinaimg.cn/mw690/a6ca17dbgy1i4x4vi732zj21400r8gtq.jpg',
          weiXiuImg: 'https://wx4.sinaimg.cn/mw690/a6ca17dbgy1i4x4vi732zj21400r8gtq.jpg',
          heGeImg: 'https://wx4.sinaimg.cn/mw600/e605b254ly1i6tld21nonj20u014013g.jpg',
          orgName: '兰山区',
          warningReason:"规定时间:3小时,时间维修时间:2小时，实际维修时间小于规定时间 1小时"
        },{
          workOrderNumber: 'TEST202510310001',
          repairSiteName: '王小虎',
          plateNo: '鲁A12345',
          orderStatus: '3',
          startTime: '2025-10-29 10:00:00',
          endTime: '2025-10-31 10:00:00',
          createTime: '2025-10-29 10:00:00',
          jinChangImg: 'https://wx2.sinaimg.cn/mw690/dcb19d29ly1i3qh75gioaj20n00gt41p.jpg',
          junGongImg: 'https://wx1.sinaimg.cn/mw690/71cea2dagy1i6qdooz0q5j20u018q0zb.jpg',
          jieSuanImg: 'https://wx4.sinaimg.cn/mw690/a6ca17dbgy1i4x4vi732zj21400r8gtq.jpg',
          weiXiuImg: 'https://wx4.sinaimg.cn/mw690/a6ca17dbgy1i4x4vi732zj21400r8gtq.jpg',
          heGeImg: 'https://wx4.sinaimg.cn/mw600/e605b254ly1i6tld21nonj20u014013g.jpg',
          orgName: '兰山区',
          warningReason:"规定时间:3小时,时间维修时间:2小时，实际维修时间小于规定时间 1小时"
        }

      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        wxCode: null,
        wxUnit: "",
        wxAddr: null,
        wxPerson: null,
        wxTel: null,
        creditCode: null,
        licensepic: null,
        legalPerson: null,
        legalTel: null,
        businessScope: null,
        orgCode: null,
        enterpriseType: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        wxUnit: [
          { required: true, message: '请输入维护站名称', trigger: 'blur' },
        ],
        wxAddr: [
          { required: true, message: '请输入维护站地址', trigger: 'blur' },
        ],
        wxPerson: [
          { required: true, message: '请输入联系人', trigger: 'blur' },
        ],
        wxTel: [
          { required: true, message: '请输入联系人电话', trigger: 'blur' },
        ],
        creditCode: [
          { required: true, message: '请输入社会统一代码', trigger: 'blur' },
        ],
        legalPerson: [
          { required: true, message: '请输入法人', trigger: 'blur' },
        ],
        legalTel: [
          { required: true, message: '请输入法人电话', trigger: 'blur' },
        ],
        businessScope: [
          { required: true, message: '请输入经营范围', trigger: 'blur' }
        ],
        enterpriseType: [
          {required: true, message: '请选择企业类型', trigger: 'change'}
        ]
      }
    };
  },
  methods: {
    dilogleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
            done();
        })
        .catch(_ => {});
    },
    handleClose(){
      this.fileList = []
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(`只能上传一个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${ file.name }？`);
    },
    uploadSuccess(response, file, fileList){
      if(response.code === 200){
        this.$message.success(response.msg);
        this.openImportData = false;
        this.fileList = fileList;
        this.getList();
      }else {
        this.$message.error(response.msg);
      }
    },

    openImport(){
      this.openImportData = true;
      this.fileList = [];
    },
    /** 查询汽车检测-二级维护站列表 */
    getList() {
      this.loading = true;
      listSecondary(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        wxCode: null,
        wxUnit: null,
        wxAddr: null,
        wxPerson: null,
        wxTel: null,
        creditCode: null,
        licensepic: null,
        legalPerson: null,
        legalTel: null,
        businessScope: null,
        orgCode: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.queryParams.orgCode) {
        this.queryParams.orgCode = this.queryParams.orgCodes.toString();
      }

      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push('/maintenanceorder/addorder/index')
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSecondary(id).then(response => {
        this.form = response.data;
        this.form.orgCodes = response.data.orgCode;
        this.open = true;
        this.title = "修改汽车检测-二级维护站";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.orgCode = this.form.orgCodes.toString();
          if (this.form.id != null) {
            updateSecondary(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSecondary(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除？').then(function() {
        return delSecondary(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('vehicleservice/secondary/export', {
        ...this.queryParams
      }, `secondary_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.inner-title{
  font-size: 17px;
  font-weight: bold;
  border-bottom: 1px solid #C0C4CC;
  padding: 15px;
  margin-bottom: 15px;
}
</style>
